package edu.whut.interview;
/*
* 求数组最大值，求和，平均值,低于平均值个数
* */
public class Demo02 {
    public static void main(String[] args) {
        int[] num={1,9,14,6,4};
        int max = getMax(num);
        System.out.println(max);

        int sum = getSum(num);
        System.out.println(sum);

        double avg = getAvg(num);
        System.out.println(avg);

        int count = getCount(num);
        System.out.println(count);

    }
    public static int getCount(int[] arr){
        int count = 0;
        double avg = getAvg(arr);
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]<avg)
                count++;
        }
        return count;
    }
    public static double getAvg(int[] arr){
        int sum = getSum(arr);
        double avg = sum*1.0/arr.length;
        return avg;
    }
    public static int getSum(int[] arr){
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        return sum;
    }
    public static int getMax(int[] arr){
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]>max){
                max = arr[i];
            }
        }
        return max;

    }
}
